<!-- 紧急医疗 紧急转院 紧急运返 陪同费 -->
<template>
    <el-card class="box-card">
        <div slot="header" class="card-heaer">
            <span style="line-height: 36px;">{{name}}理赔录入</span>
            <el-button type="primary" style="float:right" @click="up" v-if="state!='查看'&&state!='结果'">提交</el-button>
        </div>

        <rescuemove v-if="name=='紧急转院'" :modelrules="rescueMoveRules" :newState="reportState">
        </rescuemove>

        <rescueMeidcaBill v-if="name=='紧急医疗'" :modelrules="rescueMoveRules" :newState="reportState">
        </rescueMeidcaBill>
        <rescueReturned v-if="name=='紧急运返'" :modelrules="rescueMoveRules" :newState="reportState">
        </rescueReturned>

        <div class="space20">
        </div>
        <el-card class="box-card">
            <div slot="header" class="card-heaer">
                <span style="line-height: 36px;">账单信息</span>

            </div>

            <el-form ref="form" label-width="180px" v-if="state=='新增'||state=='修改'">
                <el-row type="flex" class="row-bg">
                    <el-col :span="6">
                        <el-form-item label="日期:">
                            <el-date-picker type="date" placeholder="选择日期" v-model="addtime" style="width: 100%;"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="3" :offset="2">
                        <el-button type="primary" @click="adddata">新增一天</el-button>
                    </el-col>
                </el-row>
            </el-form>
            <el-select v-model="mediacalCheck" placeholder="请审核" v-if="state=='理赔审核'||state=='医师审核'">
                <el-option label="审核通过" value="审核通过"></el-option>
                <el-option label="拒赔" value="理赔审核不通过"></el-option>
                <el-option label="退回重写" value="需理赔修改"></el-option>
            </el-select>
            <div class="space20">
            </div>
            <el-input v-model="checkReason" placeholder="原因" style="width:250px" :disabled="state=='查看'||state=='修改'" v-show="mediacalCheck=='需理赔修改'||mediacalCheck=='理赔审核不通过' || state=='查看' ||state=='修改'"></el-input>
            <div class="space20">
            </div>
            <el-collapse v-if="dataList.length>0">
                <el-collapse-item :title="data.show+'账单'" :key="data.index" v-for="(data, index) in dataList ">
                    <el-row type="flex" class="row-bg" v-if="state=='新增'||state=='修改'">

                        <el-col :span="3" :offset="2">
                            <el-button type="primary" @click="addMedia(index,data.value)">新增医疗账单</el-button>
                        </el-col>
                        <el-col :span="3" :offset="2">
                            <el-button type="primary" @click="addOther(index,data.value)">新增其他账单</el-button>
                        </el-col>
                    </el-row>
                    <div class="space20">
                    </div>
                    <el-card class="box-card" v-show="data.BILL_EMERGENCYMEDICAL.length>0||data.BILL_EMERGENCYOTHER.length>0">
                        <div v-for="(item,index2) in data.BILL_EMERGENCYMEDICAL" :key="item.BILL_EMERGENCYMEDICAL_ID">
                            <div class="space20">
                            </div>
                            <el-form :model="item" label-width="100px" ref="item" :inline="true" class="demo-ruleForm">

                                <el-form-item label="项目代码" :prop="'BILL_EMERGENCYMEDICAL_CODE'" 
                                :rules="{  required: true, message: '项目代码不能为空', trigger: 'blur'}">
                                    <el-input v-model="item.BILL_EMERGENCYMEDICAL_CODE"></el-input>
                                </el-form-item>
                                <el-form-item label="项目名称" :prop="'BILL_EMERGENCYMEDICAL_ZNAME'" 
                                :rules="{  required: true, message: '项目名称不能为空', trigger: 'blur'}">
                                    <el-input v-model="item.BILL_EMERGENCYMEDICAL_ZNAME"></el-input>
                                </el-form-item>
                                <el-form-item label="英文名称" :prop="'BILL_EMERGENCYMEDICAL_ENAME'" 
                                :rules="{required: true, message: '英文名称不能为空', trigger: 'blur' }">
                                    <el-input v-model="item.BILL_EMERGENCYMEDICAL_ENAME"></el-input>
                                </el-form-item>
                                <el-form-item label="项目描述" :prop="'BILL_EMERGENCYMEDICAL_DETIAL'" 
                                :rules="{  required: true, message: '项目描述不能为空', trigger: 'blur'}">
                                    <el-input v-model="item.BILL_EMERGENCYMEDICAL_DETIAL"></el-input>
                                </el-form-item>
                                <el-form-item label="项目单价" :prop="'BILL_EMERGENCYMEDICAL_PMONEY'" 
                                :rules="{ required: true, message: '项目单价不能为空', trigger: 'blur' }">
                                    <el-input v-model="item.BILL_EMERGENCYMEDICAL_PMONEY"></el-input>
                                </el-form-item>
                                <el-form-item label="项目数量" :prop="'BILL_EMERGENCYMEDICAL_COUNT'" :rules="{  required: true, message: '项目数量不能为空', trigger: 'blur'  }">
                                    <el-input v-model="item.BILL_EMERGENCYMEDICAL_COUNT"></el-input>
                                </el-form-item>
                                <el-form-item label="项目费用" v-if="item.BILL_EMERGENCYMEDICAL_COUNT!='' && item.BILL_EMERGENCYMEDICAL_PMONEY!=''" 
                                :prop="'BILL_EMERGENCYMEDICAL_CMONEY'">                                  
                                    <el-input v-model="item.BILL_EMERGENCYMEDICAL_CMONEY" :disabled="true"></el-input>
                                </el-form-item>

                                <!--BILL_EMERGENCYMEDICAL_STATE-->
                                <el-select v-model="item.BILL_EMERGENCYMEDICAL_STATE" placeholder="是否属于保险责任" v-if="state=='医师审核' ">
                                    <el-option label="不属于保险责任" value="不属于保险责任"></el-option>
                                    <el-option label="属于保险责任" value="属于保险责任" selected="selected"></el-option>
                                </el-select>
                                <span v-if="state=='结果' && item.BILL_EMERGENCYMEDICAL_STATE=='不属于保险责任' " style="line-height:40px; color:red">
                                    不属于保险责任，不计算
                                    </span>
                                <el-button  style="float: right; margin-right:50px;"  v-if="state!='理赔审核'  && state!='理赔审核'"
                                type="danger" @click="delectitem(index,index2)">删除</el-button>
                            </el-form>

                        </div>
                        <div class="space20">
                        </div>
                        <div v-for="(item,index2) in data.BILL_EMERGENCYOTHER" :key="item.BILL_EMERGENCYOTHER_ID">
                            <div class="space20">
                            </div>
                            <el-form ref="form" label-width="100px" :model="item" :inline="true">
                                <el-form-item label="项目名称" :prop="'BILL_EMERGENCYOTHER_NAME'" 
                                :rules="{ required: true, message: '项目名称不能为空', trigger: 'blur' }">
                                    <el-input v-model="item.BILL_EMERGENCYOTHER_NAME"></el-input>
                                </el-form-item>

                                <el-form-item label="项目金额" :prop="'BILL_EMERGENCYOTHER_MONEY'" 
                                :rules="{ required: true, message: '项目金额不能为空', trigger: 'blur' }">
                                    <el-input v-model="item.BILL_EMERGENCYOTHER_MONEY"></el-input>
                                </el-form-item>
                                <el-button style="float: right; margin-right:50px;" v-if="state!='医师审核' && state!='理赔审核'"  type="danger" 
                                @click="delectitemOther(index,index2)">删除</el-button>
                            </el-form>
                        </div>
                    </el-card>
                </el-collapse-item>
            </el-collapse>

        </el-card>
    </el-card>
</template>
<script>
import getid from '@/js/getid';
import {
    mapState
} from 'vuex';
import rescuemove from '@/components/lipei/lipeiaddReport/rescueMove'
import rescueAccompany from '@/components/lipei/lipeiaddReport/rescueAccompany'


import rescueMeidca from '@/components/lipei/lipeiaddReport/rescueMeidca'
import rescueReturned from '@/components/lipei/lipeiaddReport/rescueReturned'

export default {
    data() {
        return {
            addtime: "",
            dataList: [],
            mediacalCheck: "",
            checkReason: "",
            id: "",
            reportState: '待办任务'
        }
    },
    props: {
        name: {
            type: String,
            default: ""
        },
        state: {
            type: String,
            default: "新增"
        }
    },
    components: {
        'rescuemove': rescuemove,
        'rescueMeidcaBill': rescueMeidca,
        'rescueReturned': rescueReturned,

    },
    computed: mapState({

        //全球紧急救援-紧急医疗
        rescueMeidca: state => state.reportFormItem.rescueMeidca,
        rescueMeidcaRules: state => state.reportFormItem.rescueMeidcaRules,
        //陪同
        rescueAccompany: state => state.reportFormItem.rescueAccompany,
        rescueAccompanyRules: state => state.reportFormItem.rescueAccompanyRules,
        //全球紧急救援-紧急转院
        rescueMove: state => state.reportFormItem.rescueMove,
        rescueMoveRules: state => state.reportFormItem.rescueMoveRules,
        //全球紧急救援-紧急运返
        rescueReturned: state => state.reportFormItem.rescueReturned,
        rescueReturnedRules: state => state.reportFormItem.rescueReturnedRules,

    }),
    watch: {
        dataList: {
            handler: function(val, oldval) {
                if (val.length < 0) {
                    return;
                }
                for (var i = 0; i < val.length; i++) {

                    for (var k = 0; k < this.dataList[i].BILL_EMERGENCYMEDICAL.length; k++) {

                        this.dataList[i].BILL_EMERGENCYMEDICAL[k].BILL_EMERGENCYMEDICAL_CMONEY = this.dataList[i].BILL_EMERGENCYMEDICAL[k].BILL_EMERGENCYMEDICAL_COUNT * this.dataList[i].BILL_EMERGENCYMEDICAL[k].BILL_EMERGENCYMEDICAL_PMONEY;
                    }

                }

            },
            deep: true
        }
    },
    methods: {
        adddata() {
            var data = this.addtime;
            var month = data.getMonth() + 1;

            var strDate = data.getDate();
            var year = data.getFullYear();
            var time = year + "-" + month + "-" + strDate;
            var model = {
                show: time,
                value: data.toLocaleDateString(),
                BILL_EMERGENCYMEDICAL: [],
                BILL_EMERGENCYOTHER: []

            };
            this.addtime = "";
            this.dataList.push(model);

        },
        addMedia(index, time) {
            var model = {
                BILL_EMERGENCYMEDICAL_ID: getid.getid(),
                BILL_EMERGENCYMEDICAL_ENAME: "",
                BILL_EMERGENCYMEDICAL_ZNAME: "",
                BILL_EMERGENCYMEDICAL_MONEY: "",
                BILL_EMERGENCYMEDICAL_STATE: "",
                BILL_EMERGENCYMEDICAL_CODE: "",
                BILL_EMERGENCYMEDICAL_DETIAL: "",
                BILL_EMERGENCYMEDICAL_PMONEY: "",
                BILL_EMERGENCYMEDICAL_COUNT: "",
                BILL_EMERGENCYMEDICAL_CMONEY: "",
                RI_ID: "",
                BILL_EMERGENCYMEDICAL_TYPE: "",
                BILL_EMERGENCYMEDICAL_DATE: time,
                type: "医疗"
            };
            this.dataList[index].BILL_EMERGENCYMEDICAL.push(model);
        },
        addOther(index, time) {
            var model = {
                BILL_EMERGENCYOTHER_ID: getid.getid(),
                BILL_EMERGENCYOTHER_NAME: "",
                BILL_EMERGENCYOTHER_MONEY: "",
                BILL_EMERGENCYOTHER_TYPE: "",
                RI_ID: "",
                BILL_EMERGENCYOTHER_OTHER: "",
                BILL_EMERGENCYOTHER_DATE: time,
                type: "其他"
            };
            this.dataList[index].BILL_EMERGENCYOTHER.push(model);

        },
        up() {
            if (this.state == "新增") {
                this.addNew();
            } else {
                this.mediacalChek();
            }
        },
        mediacalChek() {
            if (this.state == "医师审核" || this.state == "理赔审核") {
                if (this.mediacalCheck == "") {
                    this.$notify({
                        title: '您还没有审核',
                        message: '您还没有审核',
                        type: 'warning'
                    });
                    return;
                }
                if (this.mediacalCheck != "审核通过" && this.checkReason == "") {
                    this.$notify({
                        title: '请填写原因',
                        message: '请填写原因',
                        type: 'warning'
                    });
                    return;
                }
            }
            var url;
            var model = {};
            switch (this.name) {
                case '紧急医疗':
                    url = "BILL_HMEDIA";
                    model.BILL_HMEDIA_ID = this.id,
                        model.RI_HMEDIA_ID = this.$route.query["id"];
                    if (this.mediacalCheck == "审核通过" && this.state == "医师审核") {
                        model.BILL_HMEDIA_STATE = "需计算";
                    }
                    else if (this.mediacalCheck == "审核通过" && this.state == "理赔审核") {
                        model.BILL_HMEDIA_STATE = "需医师审核";
                    } else {
                        if (this.state == "修改") {
                            model.BILL_HMEDIA_STATE = "需理赔审核";
                            model.BILL_HMEDIA_WHY = "";
                            if (this.rescueMeidca.RI_HMEDIA_ADDRESS && Object.prototype.toString.call(this.rescueMeidca.RI_HMEDIA_ADDRESS)=='[object Array]') {
                                this.rescueMeidca.RI_HMEDIA_ADDRESS = this.rescueMeidca.RI_HMEDIA_ADDRESS.join(",");
                            }
                            model.RI_HMEDIA = this.rescueMeidca;
                        } else {
                            model.BILL_HMEDIA_STATE = this.mediacalCheck;
                        }
                    }
                    if (this.state == "理赔审核" || this.state == "医师审核") {
                        model.BILL_HMEDIA_WHY = this.checkReason;
                    }
                    break;
                case '紧急转院':
                    url = "BILL_HCHANGE";
                    model.BILL_HCHANGE_ID = this.id,
                        model.RI_HCHANGE_ID = this.$route.query["id"];
                    if (this.mediacalCheck == "审核通过" && this.state == "医师审核") {
                        model.BILL_HCHANGE_STATE = "需计算";
                    }
                    else if (this.mediacalCheck == "审核通过" && this.state == "理赔审核") {
                        model.BILL_HCHANGE_STATE = "需医师审核";
                    } else {
                        if (this.state == "修改") {
                            model.BILL_HCHANGE_STATE = "需理赔审核";
                            model.BILL_HCHANGE_WHY = "";
                            if (this.rescueMove.RI_HCHANGE_ADDRESS && Object.prototype.toString.call(this.rescueMove.RI_HCHANGE_ADDRESS)=='[object Array]') {
                                this.rescueMove.RI_HCHANGE_ADDRESS = this.rescueMove.RI_HCHANGE_ADDRESS.join(",");
                            }
                            model.RI_HCHANGE = this.rescueMove;
                        } else {
                            model.BILL_HCHANGE_STATE = this.mediacalCheck;
                        }
                    }
                    if (this.state == "理赔审核" || this.state == "医师审核") {
                        model.BILL_HCHANGE_WHY = this.checkReason;
                    }
                    break;
                case '紧急运返':
                    url = "BILL_HBACK";
                    model.BILL_HBACK_ID = this.id,
                        model.RI_HBACK_ID = this.$route.query["id"];
                    if (this.mediacalCheck == "审核通过" && this.state == "医师审核") {
                        model.BILL_HBACK_STATE = "需计算";
                    }
                    else if (this.mediacalCheck == "审核通过" && this.state == "理赔审核") {
                        model.BILL_HBACK_STATE = "需医师审核";
                    } else {
                        if (this.state == "修改") {
                            model.BILL_HBACK_STATE = "需理赔审核";
                            model.BILL_HBACK_WHY = "";
                            if (this.rescueReturned.RI_HBACK_ADDRESS && Object.prototype.toString.call(this.rescueReturned.RI_HBACK_ADDRESS)=='[object Array]') {
                                this.rescueReturned.RI_HBACK_ADDRESS = this.rescueReturned.RI_HBACK_ADDRESS.join(",");
                            }
                            model.RI_HBACK = this.rescueReturned;
                        } else {
                            model.BILL_HBACK_STATE = this.mediacalCheck;
                        }

                    }
                    if (this.state == "理赔审核" || this.state == "医师审核") {
                        model.BILL_HBACK_WHY = this.checkReason;
                    }
                    break;
            }
            //账单id 修改 医疗相关 非医疗相关
            var BILL_EMERGENCYOTHER = [];
            var BILL_EMERGENCYMEDICAL = [];
            for (var i = 0; i < this.dataList.length; i++) {
                for (var k = 0; k < this.dataList[i].BILL_EMERGENCYOTHER.length; k++) {
                    this.dataList[i].BILL_EMERGENCYOTHER[k].RI_ID = this.id;
                    BILL_EMERGENCYOTHER.push(this.dataList[i].BILL_EMERGENCYOTHER[k]);
                }
                for (var k = 0; k < this.dataList[i].BILL_EMERGENCYMEDICAL.length; k++) {
                    this.dataList[i].BILL_EMERGENCYMEDICAL[k].RI_ID = this.id;
                    BILL_EMERGENCYMEDICAL.push(this.dataList[i].BILL_EMERGENCYMEDICAL[k]);
                }
            }
            model.BILL_EMERGENCYOTHER = BILL_EMERGENCYOTHER;
            model.BILL_EMERGENCYMEDICAL = BILL_EMERGENCYMEDICAL;


            this.$http.put(url, model).then(response => {
                var data = response.body;
                if (data.code == 1) {
                    this.$notify({
                        title: '审核成功',
                        message: '审核成功',
                        type: 'success'
                    });
                    this.$router.go(-1);
                } else {
                    this.$notify({
                        title: '提交失败',
                        message: data.msg,
                        type: 'warning'
                    });
                }
            }, response => {
                this.loading = false;
                this.$notify.error({
                    title: '网络错误',
                    message: '网络错误'
                });
            });

        },
        addNew() {
            var model = {};
            var url;
            var id = getid.getid();
            switch (this.name) {
                case '紧急医疗':
                    if (!this.rescueMeidca.RI_HMEDIA_BILLDOC) {
                        this.$notify.error({
                            title: '附件未提交',
                            message: '附件未提交'
                        });
                        return;
                    }
                    url = "BILL_HMEDIA";
                    model.BILL_HMEDIA_ID = id
                    model.RI_HMEDIA_ID = this.$route.query["id"];
                    model.BILL_HMEDIA_STATE = "医师审核";
                    if (this.rescueMeidca.RI_HMEDIA_ADDRESS && Object.prototype.toString.call(this.rescueMeidca.RI_HMEDIA_ADDRESS)=='[object Array]') {
                        this.rescueMeidca.RI_HMEDIA_ADDRESS = this.rescueMeidca.RI_HMEDIA_ADDRESS.join(",");
                    }
                    model.RI_HMEDIA = this.rescueMeidca;
                    break;
                case '紧急转院':

                    url = "BILL_HCHANGE";
                    model.BILL_HCHANGE_ID = id
                    model.RI_HCHANGE_ID = this.$route.query["id"];
                    model.BILL_HCHANGE_STATE = "医师审核";
                    if (this.rescueMove.RI_HCHANGE_ADDRESS && Object.prototype.toString.call(this.rescueMove.RI_HCHANGE_ADDRESS)=='[object Array]') {
                        this.rescueMove.RI_HCHANGE_ADDRESS = this.rescueMove.RI_HCHANGE_ADDRESS.join(",");
                    }
                    model.RI_HCHANGE = this.rescueMove;
                    break;
                case '紧急运返':

                    url = "BILL_HBACK";
                    model.BILL_HBACK_ID = id
                    model.RI_HBACK_ID = this.$route.query["id"];
                    model.BILL_HBACK_STATE = "医师审核";
                    if (this.rescueReturned.RI_HBACK_ADDRESS && Object.prototype.toString.call(this.rescueReturned.RI_HBACK_ADDRESS)=='[object Array]') {
                        this.rescueReturned.RI_HBACK_ADDRESS = this.rescueReturned.RI_HBACK_ADDRESS.join(",");
                    }
                    model.RI_HBACK = this.rescueReturned;
                    break;
            }
            var BILL_EMERGENCYOTHER = [];
            var BILL_EMERGENCYMEDICAL = [];
            for (var i = 0; i < this.dataList.length; i++) {
                for (var k = 0; k < this.dataList[i].BILL_EMERGENCYOTHER.length; k++) {
                    this.dataList[i].BILL_EMERGENCYOTHER[k].RI_ID = id;
                    BILL_EMERGENCYOTHER.push(this.dataList[i].BILL_EMERGENCYOTHER[k]);
                }
                for (var k = 0; k < this.dataList[i].BILL_EMERGENCYMEDICAL.length; k++) {
                    this.dataList[i].BILL_EMERGENCYMEDICAL[k].RI_ID = id;
                    BILL_EMERGENCYMEDICAL.push(this.dataList[i].BILL_EMERGENCYMEDICAL[k]);
                }
            }
            model.BILL_EMERGENCYOTHER = BILL_EMERGENCYOTHER;
            model.BILL_EMERGENCYMEDICAL = BILL_EMERGENCYMEDICAL;


            this.$http.post(url, model).then(response => {
                var data = response.body;
                if (data.code == 1) {
                    this.$notify({
                        title: '添加成功',
                        message: '添加成功',
                        type: 'success'
                    });
                    this.$router.go(-1);
                } else {
                    this.$notify({
                        title: '提交失败',
                        message: '提交失败',
                        type: 'warning'
                    });
                }
            }, response => {
                this.loading = false;
                this.$notify.error({
                    title: '网络错误',
                    message: '网络错误'
                });
            });
        },
        delectitem(index, index2) {
            this.dataList[index].BILL_EMERGENCYMEDICAL.splice(index2, 1);
        },
        delectitemOther(index, index2) {
            this.dataList[index].BILL_EMERGENCYOTHER.splice(index2, 1);
        },
        checkGet() {
            var url;
            switch (this.name) {
                case '紧急医疗':
                    url = "BILL_HMEDIA";
                    break;
                case '紧急转院':
                    url = "BILL_HCHANGE";
                    break;
                case '紧急运返':
                    url = "BILL_HBACK";
                    break;
            }
            this.$http.get(url + "/" + this.$route.query["id"]).then(response => {
                var data = response.body;
                if (data.code == 1) {
                    // this.$store.commit('changer', data.result[0].BILL_DATA)
                    var listMedial = data.result[0].BILL_EMERGENCYMEDICAL;
                    var listOther = data.result[0].BILL_EMERGENCYOTHER;
                    switch (this.name) {
                        case '紧急医疗':
                            this.id = data.result[0].BILL_HMEDIA_ID;
                            this.checkReason = data.result[0].BILL_HMEDIA_WHY;
                            if (data.result[0].RI_HMEDIA.RI_HMEDIA_ADDRESS) {
                                var address = data.result[0].RI_HMEDIA.RI_HMEDIA_ADDRESS.split(",");
                                address[2] = address[2] + "," + address[3];
                                address[3] = null;
                                data.result[0].RI_HMEDIA.RI_HMEDIA_ADDRESS = address;
                            }

                            this.$store.commit('rescueMeidcaChanger', data.result[0].RI_HMEDIA)

                            break;
                        case '紧急转院':
                            this.id = data.result[0].BILL_HCHANGE_ID;
                            this.checkReason = data.result[0].BILL_HCHANGE_WHY;
                            if (data.result[0].RI_HCHANGE.RI_HCHANGE_ADDRESS) {
                                var address = data.result[0].RI_HCHANGE.RI_HCHANGE_ADDRESS.split(",");
                                address[2] = address[2] + "," + address[3];
                                address[3] = null;
                                data.result[0].RI_HCHANGE.RI_HCHANGE_ADDRESS = address;
                            }

                            this.$store.commit('rescueMoveChanger', data.result[0].RI_HCHANGE)
                            break;
                        case '紧急运返':
                            this.id = data.result[0].BILL_HBACK_ID;
                            this.checkReason = data.result[0].BILL_HBACK_WHY;
                            if (data.result[0].RI_HBACK.RI_HBACK_ADDRESS) {
                                var address = data.result[0].RI_HBACK.RI_HBACK_ADDRESS.split(",");
                                address[2] = address[2] + "," + address[3];
                                address[3] = null;
                                data.result[0].RI_HBACK.RI_HBACK_ADDRESS = address;
                            }
                          
                            this.$store.commit('rescueReturnedChanger', data.result[0].RI_HBACK)
                            break;
                    }
                    var s = new Set();
                    var sname = new Set();
                    if (listMedial != null) {
                        for (var i = 0; i < listMedial.length; i++) {

                            s.add(listMedial[i].BILL_EMERGENCYMEDICAL_DATE); // showlist[]
                            sname.add(listMedial[i].BILL_EMERGENCYMEDICAL_DATE);
                        }
                    }
                    if (listOther != null) {
                        for (var i = 0; i < listOther.length; i++) {

                            s.add(listOther[i].BILL_EMERGENCYOTHER_DATE); // showlist[]
                            sname.add(listOther[i].BILL_EMERGENCYOTHER_DATE);
                        }
                    }
                    var list = [];
                    var sarry = Array.from(s);
                    var snamearry = Array.from(sname);
                    for (var i = 0; i < sarry.length; i++) {

                        var model = {
                            show: snamearry[i],
                            value: sarry[i],
                            BILL_EMERGENCYMEDICAL: [],
                            BILL_EMERGENCYOTHER: []

                        };
                        list.push(model);
                    }
                    if (listMedial != null) {
                        for (var i = 0; i < listMedial.length; i++) {
                            for (var k = 0; k < list.length; k++) {
                                if (listMedial[i].BILL_EMERGENCYMEDICAL_DATE == list[k].value) {
                                    listMedial[i].BILL_EMERGENCYMEDICAL_STATE = "属于保险责任";
                                    list[k].BILL_EMERGENCYMEDICAL.push(listMedial[i]);
                                }
                            }
                        }
                    }
                    if (listOther != null) {
                        for (var i = 0; i < listOther.length; i++) {
                            for (var k = 0; k < list.length; k++) {
                                if (listOther[i].BILL_EMERGENCYOTHER_DATE == list[k].value) {
                                    list[k].BILL_EMERGENCYOTHER.push(listOther[i]);
                                }
                            }
                        }

                    }
                    this.dataList = list;
                }
            }, response => {
                this.$notify.error({
                    title: '网络错误',
                    message: '网络错误'
                });
                this.loding = false;
            });
        }
    },

    activated() {
       
        switch (this.name) {
            case "紧急医疗":
                this.$store.commit('rescueMeidcaChanger', {})
                break;
            case "紧急转院":
                this.$store.commit('rescueMoveChanger', {})
                break;
            case "紧急运返":
                this.$store.commit('rescueReturnedChanger', {})
                break;

        }
        if (this.state == "新增" || this.state == "修改") {
            this.reportState = '待办任务';
        }
        if (this.state == "理赔审核" || this.state == "医师审核" || this.state == "查看" || this.state == "结果") {
            this.reportState = '审核';
        }
        this.$http.get("Ri_H/?id=" + this.$route.query["id"] + "&type=" + this.name).then(response => {
            var data = response.body;
            if (data.code == 1) {

                if (data.result[0].RI_HCHANGE_ADDRESS) {
                    var address = data.result[0].RI_HCHANGE_ADDRESS.split(",");
                    address[2] = address[2] + "," + address[3];
                    address[3] = null;
                    data.result[0].RI_HCHANGE_ADDRESS = address;
                }
                if (data.result[0].RI_HMEDIA_ADDRESS) {
                    var address = data.result[0].RI_HMEDIA_ADDRESS.split(",");
                    address[2] = address[2] + "," + address[3];
                    address[3] = null;
                    data.result[0].RI_HMEDIA_ADDRESS = address;
                }

                if (data.result[0].RI_HBACK_ADDRESS) {
                    var address = data.result[0].RI_HBACK_ADDRESS.split(",");
                    address[2] = address[2] + "," + address[3];
                    address[3] = null;
                    data.result[0].RI_HBACK_ADDRESS = address;
                }

                switch (this.name) {
                    case "紧急医疗":
                        this.$store.commit('rescueMeidcaChanger', data.result[0])
                        break;
                    case "紧急转院":
                        this.$store.commit('rescueMoveChanger', data.result[0])
                        break;
                    case "紧急运返":
                        this.$store.commit('rescueReturnedChanger', data.result[0])
                        break;


                }
            }
        }, response => {
            this.$notify.error({
                title: '网络错误',
                message: '网络错误'
            });
        })
        this.dataList = [];
        //新增/医师审核/理赔审核/修改
        if (this.state != "新增") {
            this.checkGet();

        } else {


        }


    }

}
</script>

